package part3collection;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: 线程不安全的集合
 */
public class UnsafeList {


    public static void main(String[] args) throws InterruptedException {
        List<String> list = new ArrayList<>();

        for (int i = 0; i < 2000; i++) {
            new Thread(() -> {
                synchronized (list) {
                    list.add(Thread.currentThread().getName());
                }
            }).start();
        }
        System.out.println(list.size());
    }

}
